package controllers

import (
	"fmt"
	"mywails/main/code/config/global"

	"gorm.io/gorm"
)

type TestController struct{}

func NewTestController() *TestController {
	return &TestController{}
}

func (c *TestController) TestHello() string {
	return "Hello, World!"
}

func (c *TestController) TestReturnSlice() any {
	return []string{"apple", "banana", "orange"}
}

func (c *TestController) TestInput(name string, age uint) any {
	return map[string]any{
		"name": name,
		"age":  age,
	}
}

type Info struct {
	Name string
	Age  uint
}

func (c *TestController) TestInputStruct(info Info) {
	fmt.Println(info.Name, info.Age)
}

func (c *TestController) TestCreateUser() any {
	type User struct {
		gorm.Model
		Name string
		Age  uint
	}
	db := global.DB
	db.AutoMigrate(&User{})
	db.Create(&User{Name: "John", Age: 25})
	db.Create(&User{Name: "Jane", Age: 30})
	var users []User
	db.Find(&users)
	return users
}

type Model struct {
	gorm.Model
	Name string
	Age  uint
}

func (c *TestController) TestGormModel(model Model) any {
	fmt.Println(model)
	fmt.Println("Model ID:", model.ID)
	fmt.Println("Model Name:", model.Name)
	fmt.Println("Model Age:", model.Age)
	return model
}
